﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;


namespace TicketSellingServer
{
    [ServiceContract]
    public interface ITicketSellingService
    {
        
        [OperationContract]
        SellerFlightsList SearchTickets(string date, string source, string destination);

        [OperationContract]
        string ReserveTicket(string flight, string date);

        [OperationContract]
        void CancelTicket(string reservationID);

    }


    [DataContract]
    public class SellerFlightInfo
    {
        [DataMember]
        public Uri Id { get; set; }

        [DataMember]
        public String Company { get; set; }

        [DataMember]
        public String Flight { get; set; }

        [DataMember]
        public String Source { get; set; }

        [DataMember]
        public String Destination { get; set; }

        [DataMember]
        public String Date { get; set; }

        [DataMember]
        public string Seats { get; set; }

        [DataMember]
        public string Price { get; set; }


        public int ReservedSeats { get; set; }


        public int AvailiableSeats
        {
            get { return Convert.ToInt32(Seats) - ReservedSeats; }
        }


        public override string ToString()
        {
            return Company + " " + Flight + " " + Source + " " + Destination + " " + Date + " " + Seats + " " + Price;
        }


        public SellerFlightInfo() { }

        public SellerFlightInfo(SellerFlightInfo ticket)
        {
            Company = ticket.Company;
            Flight = ticket.Flight;
            Source = ticket.Source;
            Destination = ticket.Destination;
            Date = ticket.Date;
            Seats = ticket.Seats;
            Price = ticket.Price;
            ReservedSeats = ticket.ReservedSeats;
        }
    }



    [CollectionDataContract]
    public class SellerFlightsList : List<SellerFlightInfo>
    {
        public SellerFlightsList() { }
        public SellerFlightsList(List<SellerFlightInfo> tickets) : base(tickets) { }
    }

}


